using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ConsoleApplication2.Models.Mapping
{
    public class DIAGNOSISMap : EntityTypeConfiguration<DIAGNOSIS>
    {
        public DIAGNOSISMap()
        {
            // Primary Key
            this.HasKey(t => t.ID);

            // Properties
            this.Property(t => t.CODE)
                .HasMaxLength(35);

            this.Property(t => t.DIAGNOSIS1)
                .HasMaxLength(200);

            this.Property(t => t.ADiagnosis)
                .HasMaxLength(200);

            this.Property(t => t.DIAGNOSIS_Type)
                .HasMaxLength(10);

            // Table & Column Mappings
            this.ToTable("DIAGNOSIS");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.CODE).HasColumnName("CODE");
            this.Property(t => t.TYPE).HasColumnName("TYPE");
            this.Property(t => t.CATEGORY).HasColumnName("CATEGORY");
            this.Property(t => t.DIAGNOSIS1).HasColumnName("DIAGNOSIS");
            this.Property(t => t.TPI).HasColumnName("TPI");
            this.Property(t => t.ADiagnosis).HasColumnName("ADiagnosis");
            this.Property(t => t.DIAGNOSIS_Type).HasColumnName("DIAGNOSIS_Type");

            // Relationships
            this.HasOptional(t => t.DiagnosisCateg)
                .WithMany(t => t.DIAGNOSes)
                .HasForeignKey(d => d.CATEGORY);
            this.HasOptional(t => t.DiagnosisType)
                .WithMany(t => t.DIAGNOSes)
                .HasForeignKey(d => d.TYPE);

        }
    }
}
